﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SSMoveToAction : SSAction {
    protected SSMoveToAction() {}

    protected Vector3 target;
    protected float speed;
    protected GameObject subject;

    public void Init(Vector3 target, float speed, GameObject subject, int identifier = 0, ISSActionCallback callback = null) {
        base.Init(identifier, callback);
        this.target = target;
        this.speed = speed;
        this.subject = subject;
    }

    public static SSMoveToAction GetSSAction() {
        SSMoveToAction action = ScriptableObject.CreateInstance<SSMoveToAction>();
        return action;
    }

    public override void Update() {
        subject.transform.position = Vector3.MoveTowards(subject.transform.position, target, speed * Time.deltaTime);
        if (subject.transform.position == target) {
            SetOver(true);
            SendCompleteEvent(subject);
        }
    }
}
